<template>
    <div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.content" placeholder="记录" class="handle-input"></el-input>
                <el-date-picker v-model="value1" type="datetimerange" range-separator="至" start-placeholder="开始日期"
                                end-placeholder="结束日期" class="margin10"></el-date-picker>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch" class="margin10">搜索
                </el-button>
<!--                <el-button type='primary' @click='CliExport'>导出</el-button>-->
            </div>
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    element-loading-text="拼命加载中"
                    element-loading-spinner="el-icon-loading"
                    element-loading-background="rgba(0, 0, 0, 0.8)"
                    v-loading="loading"
                    header-cell-class-name="table-header">
                <el-table-column prop="id" label="序号" align="center"></el-table-column>
                <el-table-column prop="nick_name" label="用户名" align="center"></el-table-column>
                <el-table-column prop="ip" label="IP" align="center"></el-table-column>
                <el-table-column prop="content" label="记录" align="center"></el-table-column>
                <el-table-column prop="create_time" label="操作时间" align="center"></el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex"
                               :page-size="query.pageSize" :total="pageTotal"
                               @current-change="handlePageChange"></el-pagination>
            </div>

        </div>

    </div>
</template>

<script>
import {
    Loading
} from 'element-ui';
import AxiosPost from '../api/index'

export default {
    name: 'DoLogList',
    data() {
        return {
            value1: [],
            query: {
                is_dc: 0,
                content: '',
                start_time: '',
                end_time: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [],
            pageTotal: 0,
            loading: true
        };
    },
    created() {
        this.getData();
    },
    methods: {
        handleSearch() {
            this.query.is_dc = 0
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        async CliExport() {
            this.query.is_dc = 1
            let info = await AxiosPost('/admin/log_manage/adminoperationlog', this.query)
            if (info.code !== 10000) {
                this.$message.error(info.message)
                return false
            }
            window.location.href = "https://" + info.data.data;
        },
        async getData() {
            this.query.is_dc = 0
            this.loading = true
            if(this.value1 &&this.value1.length>0){
                this.query.start_time = this.value1[0]/1000
                this.query.end_time = this.value1[1]/1000
            }else{
                this.query.start_time = ''
                this.query.end_time = ''
            }
            let info = await AxiosPost('/admin/log_manage/adminoperationlog', this.query)
            if (info.code !== 10000) {
                this.$message.error(info.message)
                return false
            }
            this.loading = false
            info.data.list.forEach(item => {
                item.create_time = this.$moment(item.create_time * 1000).format('YYYY-MM-DD HH:mm:ss')
            })
            this.tableData = info.data.list
            this.pageTotal = info.data.meta.total;
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
//时间戳转换
</script>

<style scoped>
.handle-input {
    width: 300px;
    display: inline-block;
}

.handle-box {
    margin-bottom: 20px;
}

.table {
    width: 100%;
    font-size: 14px;
}

.margin10 {
    margin-left: 10px;
}

</style>
